<?php
if (!defined('IN_XLP')) {
    exit('Access Denied');
}
$Document = array(
    'pageid' => 'home-stat', //页面标示
    'pagename' => '访问统计', //当前页面名称
    'mycss' => array(), //加载的css样式表
    'myjs' => array('content/Chart.min'), //加载的js脚本
	'footerjs'=>array(),
    'head' => true, //加载头部文件
);

include getTpl('header', 'public');
?>
<!--顶部导航 开始-->
<?php include getTpl('top', 'public');?>
<!--顶部导航 结束-->
<!--左侧菜单 开始-->
<?php include getTpl('nav', 'public');?>
<!--左侧菜单 结束-->
<!--主体 开始-->
<!-- content -->

<section id="content">
  <section class="main padder">
    <div class="clearfix">
      <?php
	switch (date("w",$rs['infotime'])){
	case 0:
	  $xq="天";
	  break;  
	case 1:
	  $xq="一";
	  break;
	case 2:
	  $xq="二";
	  break;  
	case 3:
	  $xq="三";
	  break;
	case 4:
	  $xq="四";
	  break;  
	case 5:
	  $xq="五";
	  break;
	case 6:
	  $xq="六";
	  break;
	}
?>
      <h4><i class="fa fa-table"></i><?php echo ($rs['infotime']?outTime($rs['infotime'],2):'')." (星期".$xq.") 数据统计详情";?><a href="<?php echo U('home/stat');?>" style=" float:right; margin-right:1em; cursor:pointer;">返回</a></h4>
    </div>
    <!--0-->
    <section class="panel"  style="padding-bottom:10px">
      <div class="panel-body" style="padding-bottom:0">
        <div class="col-sm-2">
          <?php
		  if($rs['id']!=$rs['lastdid']){
		  ?>
          <a class="btn btn-default" href="<?php echo U('home/stat',array("id"=>$rs['id']+1));?>" style="margin-right:1em;">后一天</a>
          <?php
		  }
		  if($rs['id']!=1){
		  ?>
          <a class="btn btn-default" href="<?php echo U('home/stat',array("id"=>$rs['id']-1));?>">前一天</a>
          <?php
		  }
		  ?>
        </div>
      </div>
      </div>
    </section>
    <!--0--> 
    <!--1-->
    <div class="row">
      <div class="col-md-4">
        <section class="panel">
          <div class="panel-body">
            <div style="height:220px"> 
              <!---->
              <div style="margin:0; float:left; width:40%">
                <p>消息分类</p>
                <br/>
                <p>总消息：<?php echo $msg['total']; ?></p>
                <p>文本：<?php echo $msg['msg2']; ?></p>
                <p>菜单：<?php echo $msg['msg1']; ?></p>
                <p>关注：<?php echo $msg['msg8']; ?></p>
                <p>取消关注：<?php echo $msg['msg9']; ?></p>
              </div>
              <div style="float:right; position:relative;">
                <canvas id="chart1" width="200" height="200"/>
              </div>
              <!----> 
            </div>
          </div>
        </section>
      </div>
      <div class="col-md-4">
        <section class="panel">
          <div class="panel-body">
            <div style="height:220px"> 
              <!---->
              <div style="margin:0; float:left; width:40%">
                <p>当日用户<br/>
                  增减情况</p>
                <br/>
                <p>新增：<?php echo $rs['new_user']; ?></p>
                <p>流失：<?php echo $rs['today_new_cancel']; ?></p>
                <p>净增加：<?php echo $rs['new_user']-$rs['today_new_cancel']; ?></p>
              </div>
              <div style="float:right; position:relative;"> <span style="position:absolute; left:50%; top:50%; text-align:center; font-size:14px; margin-top:-14px; margin-left:-35px;">当日流失率<br/>
                <?php echo ceil($rs['today_new_cancel']/$rs['new_user']*100)."%"; ?></span>
                <canvas id="chart2" width="200" height="200"/>
              </div>
              <!----> 
            </div>
          </div>
        </section>
      </div>
      <div class="col-md-4">
        <section class="panel">
          <div class="panel-body">
            <div style="height:220px"> 
              <!---->
              <div style="margin:0; float:left; width:40%">
                <p>当日用户<br/>
                  入住情况</p>
                <br/>
                <p>入住：<?php echo $rs['isbind']; ?></p>
                <p>未入住：<?php echo $rs['new_user']-$rs['isbind']; ?></p>
              </div>
              <div style="float:right; position:relative;"> <span style="position:absolute; left:50%; top:50%; text-align:center; font-size:14px; margin-top:-14px; margin-left:-35px;">当日入住率<br/>
                <?php echo ceil($rs['isbind']/$rs['new_user']*100)."%"; ?></span>
                <canvas id="chart3" width="200" height="200"/>
              </div>
              <!----> 
            </div>
          </div>
        </section>
      </div>
    </div>
    <!--1--> 
    <!--2-->
    <div class="row">
      <div class="col-md-4">
        <section class="panel">
          <div class="panel-body">
            <div style="height:220px"> 
              <!---->
              <div style="margin:0; float:left; width:40%">
                <p>来源分布</p>
                <br/>
                <p>微信关注：<?php echo $rs['source0']; ?></p>
                <p>二维码扫描<?php echo $rs['source1']; ?></p>
                <p>网站二维码<?php echo $rs['source2']; ?></p>
                <p>其他：<?php echo $rs['source3']; ?></p>
              </div>
              <div style="float:right; position:relative;">
                <canvas id="chart4" width="200" height="200"/>
              </div>
              <!----> 
            </div>
          </div>
        </section>
      </div>
      <div class="col-md-4">
        <section class="panel">
          <div class="panel-body">
            <div style="height:220px"> 
              <!---->
              <div style="margin:0; float:left; width:40%">
                <p>当日新增用户所<br/>
                  属服务中心占比</p>
                <br/>
                <?php
					foreach($rs['service'] as $rkk=>$rvv){
                ?>
                <p><?php echo isset($rvv['name'])?$rvv['name']:'数据获取错误'; ?>：<?php echo $rvv['count']; ?></p>
                <?php
					}
                ?>
              </div>
              <div style="float:right; position:relative;"> <span style="position:absolute; left:50%; top:50%; text-align:center; font-size:14px; margin-top:-14px; margin-left:-42px;">服务社覆盖率<br/>
                <?php echo ceil(($rs['servicetotal']-$rs['service'][0]['count'])/$rs['servicetotal']*100)."%"; ?></span>
                <canvas id="chart5" width="200" height="200"/>
              </div>
              <!----> 
            </div>
          </div>
        </section>
      </div>
      <div class="col-md-4">
        <section class="panel">
          <div class="panel-body">
            <div style="height:220px"> 
              <!---->
              <div style="margin:0; float:left; width:40%">
                <p>入住用户取消占比</p>
                <br/>
                <p>入住未开通服务区：<?php echo $isbindMsg['isbind']['unopen']; ?></p>
                 <p>入住已开通服务区：<?php echo $isbindMsg['isbind']['open']; ?></p>
                  <p>未入住：<?php echo $isbindMsg['unisbind']; ?></p>
              </div>
              <div style="float:right; position:relative;"> <span style="position:absolute; left:50%; top:50%; text-align:center; font-size:14px; margin-top:-14px; margin-left:-42px;">入住用户取消占比<br/>
                <?php echo ceil(($isbindMsg['isbind']['unopen']+$isbindMsg['isbind']['open'])/($isbindMsg['isbind']['unopen']+$isbindMsg['isbind']['open']+$isbindMsg['unisbind'])*100)."%"; ?></span>
                <canvas id="chart8" width="200" height="200"/>
              </div>
              <!----> 
            </div>
          </div>
        </section>
      </div>
      
    </div>
    <!--2--> 
    <!--3-->
    <div class="row">
      <div class="col-md-8">
        <section class="panel">
          <div class="panel-body">
            <div style="height:250px"> 
              <!---->
              <div style="margin:0">
                <div style="float:right; position:relative;"> <span style="position:absolute; left:10%; top:0; text-align:center; font-size:14px; margin-top:-14px; margin-left:-42px;">用户关注时间段</span>
                  <canvas id="chart7" width="780" height="250"/>
                </div>
              </div>
              <!----> 
            </div>
          </div>
        </section>
      </div>
      <div class="col-md-4">
        <section class="panel">
<header class="panel-heading">入住前十小区</header> 
     <section style="height:265px" class="panel-body scrollbar scroll-y m-b"> 
     <div class="table-responsive"> 
      <table cellpadding="0" cellspacing="0" border="" width="80%">
		  <?php
		  //for($i=0; $i<10; $i++){
		  foreach($rs['vtop'] as $rk=>$rv){
			  if($rk<=9){
		  ?>
          <tr>
            <td width="10%"><?php echo $rk+1; ?></td>
            <td width="55%"><?php echo $rv['name'];?></td>
            <td width="15%"><?php echo $rv['count']; ?>人</td>
            <td width="20%"><?php if($rv['is_open']){echo '<span style="color:green;">已开通</span>';}else{echo '<span style="color:red;">未开通</span';}; ?></td>
          </tr>
          <?php
			  }else{
				  break;	
			  }
		  }
		  ?>
        </table>
         </div>
         </section>
        </section>
      </div>
    </div>
    <!--3--> 
    <!--4-->
    <div class="row">
    <div class="col-md-12">
    <section class="panel">
    <header class="panel-heading">取消关注用户</header> 
     <section style="height:400px" class="panel-body scrollbar scroll-y m-b"> 
     <div class="table-responsive"> 
      <table cellpadding="0" cellspacing="0" border="" width="90%">
        <thead>
          <tr>
            <th align="center">来源</th>
            <th align="center">昵称</th>
            <th align="center">小区</th>
            <th align="center">邀请人</th>
            <th align="center">关注时间</th>
            <th align="center">取消关注时间</th>
          </tr>
        </thead>
        <tbody>
          <?php
               foreach($unsubscribe as $unk=>$unv){
           ?>
          <tr>
            <td width="15%"><?php echo $regType[$unv['source_id']]; ?></td>
            <td width="15%"><?php echo $unv['nickname']?$unv['nickname']:'无';?></td>
            <td width="15%"><?php echo $unv['title']?$unv['title']:'未入住'; ?></td>
            <td width="15%"><?php echo $unv['invite_uid']?getUser($unv['invite_uid']):'无'; ?></td>
            <td width="20%"><?php echo $unk?outTime($unk):'无'; ?></td>
            <td width="20%"><?php echo $unv['unsubscribe_time']?outTime($unv['unsubscribe_time']):'无'; ?></td>
          </tr>
          <?php
              }
          ?>
        </tbody>
      </table>
         </div>
         </section>
        </section>
      </div>
    </div>
    <!--4--> 
        <!--4-->
    <div class="row">
    <div class="col-md-12">
    <section class="panel">
    <header class="panel-heading">当日邀请关注人数对比</header> 
     <section style="height:400px" class="panel-body scrollbar scroll-y m-b"> 
     <div class="table-responsive"> 
      <table cellpadding="0" cellspacing="0" border="" width="90%">
        <thead>
          <tr>
            <th align="center">邀请人</th>
            <th align="center">邀请人数</th>
            <th align="center">入住人数</th>
            <th align="center">未入住人数</th>
          </tr>
        </thead>
        <tbody>
          <?php
          if($inviteinfo){
                  $uid=$inviteinfo['uid'];
               foreach($uid as $ik=>$iv){
                       if($ik>0){
           ?>
          <tr>
            <td width="25%"><?php echo $ik?getUser($ik):'没有邀请人'; ?></td>
            <td width="25%"><?php echo $iv?$iv.'人':0;?></td>
             <td width="25%"><?php echo $inviteinfo[$ik]['isbind']?$inviteinfo[$ik]['isbind'].'人':0; ?></td>
            <td width="25%"><?php echo $inviteinfo[$ik]['unisbind']?$inviteinfo[$ik]['unisbind'].'人':0; ?></td>
          </tr>
          <?php
                       } } }  else {?>
         <tr><td colspan="4" align="center">今天没有暂无记录</td></tr>
            <?php }?>
        </tbody>
      </table>
         </div>
         </section>
        </section>
      </div>
    </div>
    <!--4--> 
  </section>
  <!--/ main padder --> 
</section>
<!--/ content --> 
<!--主体 结束--> 
<script>
var doughnutData1 = [
	{
		value: <?php echo $msg['msg2']; ?>,
		color:"#F7464A",
		highlight: "#FF5A5E",
		label: "文本"
	},
	{
		value: <?php echo $msg['msg1']; ?>,
		color: "#46BFBD",
		highlight: "#5AD3D1",
		label: "菜单"
	},
	{
		value: <?php echo $msg['msg8']; ?>,
		color: "#FDB45C",
		highlight: "#FFC870",
		label: "关注"
	},
	{
		value: <?php echo $msg['msg9']; ?>,
		color: "#949FB1",
		highlight: "#A8B3C5",
		label: "取消关注"
	}

];
var doughnutData2 = [
	{
		value: <?php echo $rs['today_new_cancel']; ?>,
		color:"#F7464A",
		highlight: "#FF5A5E",
		label: "流失"
	},
	{
		value: <?php echo $rs['new_user']-$rs['today_new_cancel']; ?>,
		color: "#46BFBD",
		highlight: "#5AD3D1",
		label: "净增加"
	}

];
var doughnutData3 = [
	{
		value: <?php echo $rs['isbind']; ?>,
		color: "#FDB45C",
		highlight: "#FFC870",
		label: "入住"
	},
	{
		value: <?php echo $rs['new_user']-$rs['isbind']; ?>,
		color: "#46BFBD",
		highlight: "#5AD3D1",
		label: "未入住"
	}

];
var doughnutData4 = [
	{
		value: <?php echo $rs['source0']; ?>,
		color:"#F7464A",
		highlight: "#FF5A5E",
		label: "微信关注"
	},
	{
		value: <?php echo $rs['source1']; ?>,
		color: "#46BFBD",
		highlight: "#5AD3D1",
		label: "二维码扫描"
	},
	{
		value: <?php echo $rs['source2']; ?>,
		color: "#FDB45C",
		highlight: "#FFC870",
		label: "网站二维码"
	},
	{
		value: <?php echo $rs['source3']; ?>,
		color: "#949FB1",
		highlight: "#A8B3C5",
		label: "其他"
	}

];
var doughnutData8 = [
	{
		value: <?php echo $isbindMsg['isbind']['open']; ?>,
		color:"#F7464A",
		highlight: "#FF5A5E",
		label: "入住已开通"
	},
	{
		value: <?php echo $isbindMsg['isbind']['unopen'];  ?>,
		color: "#46BFBD",
		highlight: "#5AD3D1",
		label: "入住未开通"
	},
	{
		value: <?php echo $isbindMsg['unisbind'];  ?>,
		color: "#FDB45C",
		highlight: "#FFC870",
		label: "未入住已开通"
	}
];
var color = [{"color":"#F7464A","highlight":"#FF5A5E"},
			 {"color":"#46BFBD","highlight":"#5AD3D1"},
			 {"color":"#FDB45C","highlight":"#FFC870"},
			 {"color":"#949FB1","highlight":"#A8B3C5"},
			 {"color":"#4D5360","highlight":"#626979"},];
var doughnutData5 = [
		<?php
		foreach($rs['service'] as $rkk=>$rvv){
		?>
		{value: <?php echo $rvv['count']; ?>,color:color[<?php echo $rkk; ?>].color,highlight: color[<?php echo $rkk; ?>].highlight,label: "<?php echo isset($rvv['name'])?$rvv['name']:'错误'; ?>"},
		<?php
		}
		?>

	];	
var barChartData = {
labels : ["0点","1点","2点","3点","4点","5点","6点","7点","8点","9点","10点","11点","12点","13点","14点","15点","16点","17点","18点","19点","20点","21点","22点","23点"],
datasets : [
	{
		fillColor : "rgba(151,187,205,0.5)",
		strokeColor : "rgba(151,187,205,0.8)",
		highlightFill : "rgba(151,187,205,0.75)",
		highlightStroke : "rgba(151,187,205,1)",
		data : [<?php
						foreach($rs['hour'] as $rk=>$rv){
						echo $rv.",";
						}
						?>]			
	}
]

}
window.onload = function(){
	var ctx1 = document.getElementById("chart1").getContext("2d");
	window.myDoughnut1 = new Chart(ctx1).Doughnut(doughnutData1, {responsive : true});
	var ctx2 = document.getElementById("chart2").getContext("2d");
	window.myDoughnut2 = new Chart(ctx2).Doughnut(doughnutData2, {responsive : true});
	var ctx3 = document.getElementById("chart3").getContext("2d");
	window.myDoughnut3 = new Chart(ctx3).Doughnut(doughnutData3, {responsive : true});
	var ctx4 = document.getElementById("chart4").getContext("2d");
	window.myDoughnut4 = new Chart(ctx4).Doughnut(doughnutData4, {responsive : true});
	
	var ctx5 = document.getElementById("chart5").getContext("2d");
	window.myDoughnut5 = new Chart(ctx5).Doughnut(doughnutData5, {responsive : true});
	
	var ctx7 = document.getElementById("chart7").getContext("2d");
	window.myBar = new Chart(ctx7).Bar(barChartData, {
		responsive : true
	});
var ctx8 = document.getElementById("chart8").getContext("2d");
	window.myDoughnut8 = new Chart(ctx8).Doughnut(doughnutData8, {responsive : true});
};
$(function(){
	
})
</script>
<?php
include getTpl('footer', 'public');
?>
